var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2ADManager = require("ADManager");
var $2XiaoMiAD = require("XiaoMiAD");
var $2XiaoMiConstant = require("XiaoMiConstant");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_XiaoMiNative = /* */function (_cc$Component83) {
  babel_inherits(c, _cc$Component83);
  var _super102 = babel_createSuper(c);
  function c() {
    var _this241;
    babel_classCallCheck(this, c);
    _this241 = _super102.apply(this, arguments);
    _this241.image = null;
    _this241.title = null;
    _this241.desc = null;
    return _this241;
  }
  babel_createClass(c, [{
    key: "onLoad",
    value: function onLoad() {
      if ($2ADManager.default.instance.sdkType == $2ADManager.SDK_TYPE.XiaoMi && $2XiaoMiAD.default.canShowInsertXiaoMi()) {
        $2ADManager.default.instance.isTest || this.createAD();
      } else {
        this.node.destroy();
      }
    }
  }, {
    key: "createAD",
    value: function createAD() {
      this.hideNode();
      $2ADManager.default.instance.isTest || this.creatNativeAD();
    }
  }, {
    key: "creatNativeAD",
    value: function creatNativeAD() {
      console.log("create====12");
      var e = this;
      this._native = qg.createNativeAd({
        adUnitId: $2XiaoMiConstant.default.POSID_NativeAD
      });
      this._native.load();
      if (this._native) {
        console.log("naitve===");
        this._native.onLoad(function (t) {
          e._nativeCurrentAdList = t.adList.pop();
          e.showNativeAd();
        });
      }
      this._native.onError(function (t) {
        console.log("oppoNativeBanner： 原生广告加载失败，错误码：" + JSON.stringify(t));
        e.hideNode();
      });
    }
  }, {
    key: "showNativeAd",
    value: function showNativeAd() {
      var _this242 = this;
      var e;
      e = this._nativeCurrentAdList.imgUrlList[0];
      if (!e) {
        e = this._nativeCurrentAdList.icon;
      }
      var t = ".png";
      -1 != e.indexOf(".jpg") && (t = ".jpg");
      if (e) {
        cc.assetManager.loadRemote(e, {
          ext: t
        }, function (e, t) {
          if (e) {
            console.log("err==", e);
            return void _this242.hideNode();
          }
          var a = new cc.SpriteFrame(t);
          _this242.image.spriteFrame = a;
          _this242._native.reportAdShow({
            adId: _this242._nativeCurrentAdList.adId
          });
          _this242.showNode();
        });
      } else {
        this.hideNode();
      }
    }
  }, {
    key: "clickNativeAd",
    value: function clickNativeAd() {
      this._native && this._native.reportAdClick({
        adId: this._nativeCurrentAdList.adId
      });
    }
  }, {
    key: "showNode",
    value: function showNode() {
      this.node.active = true;
    }
  }, {
    key: "hideNode",
    value: function hideNode() {
      this.node.active = false;
    }
  }]);
  return c;
}(cc.Component);
cc__decorate([ccp_property(cc.Sprite)], def_XiaoMiNative.prototype, "image", undefined);
cc__decorate([ccp_property(cc.Label)], def_XiaoMiNative.prototype, "title", undefined);
cc__decorate([ccp_property(cc.Label)], def_XiaoMiNative.prototype, "desc", undefined);
def_XiaoMiNative = cc__decorate([ccp_ccclass], def_XiaoMiNative);
exports.default = def_XiaoMiNative;